/**
 * 
 */
package com.moco.launcher.view;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Handler;
import android.util.Log;
import android.view.View;


public class DrawView extends View
{
	public float currentX = 40;
	public float currentY = 50;
	public int circle=8;
	private Paint p = new Paint();
	private int alpha=100; 
	Timer timer=new Timer();
	TimerTask task=null;
	Handler handler=new Handler(){
		public void handleMessage(android.os.Message msg) {
			if(msg.what==1){
				Log.d("WGZ", "handler=");
				if (alpha<100)
				postInvalidate();
			}else if(msg.what==2){
				setVisibility(View.GONE);
			}
//			invalidate();
		};
	};
	
	public DrawView(Context context)
	{
		super(context);
		setVisibility(View.GONE);
		// TODO Auto-generated constructor stub
	}
	@Override
	public void onDraw (Canvas canvas)
	{
		Log.d("WGZ", "onDraw=");
		super.onDraw(canvas);
		p.setARGB(255, 240, 130, 25);
		canvas.drawCircle(currentX , currentY , circle*alpha/50 , p);
		Log.d("WGZ","currentX == "+currentX+"currentY== "+currentY);
//		canvas.drawCircle(currentX , currentY , circle , p);		
	}
	public void showAnim(){
		setVisibility(View.VISIBLE);
		if(timer!=null){
			if(task!=null){
				task.cancel();
			}
//			timer.cancel();
		}
		task=new TimerTask() {
			@Override
			public void run() {
				Log.d("WGZ", "alpha=="+alpha);
				if(alpha<100){
					alpha= alpha+3;
					p.setAlpha(alpha);
					handler.sendEmptyMessage(1);
				}else{
					task.cancel();
					alpha=0;
					handler.sendEmptyMessage(2);
					
				}
				
			}
		};
		timer.schedule(task, 0,10);		
	}
}
